package six_dirct_Exchange;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import util.RabbitMqUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @BelongsProject: RabbitMQ
 * @BelongsPackage: five_publishAndSubscribe
 * @Author: HUI
 * @CreateTime: 2022-04-13 20:00
 * @Description: 发布者
 */
public class LogsProducer {
    private static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明一个 Exchange，名字、类型
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);


        Map<String, String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("info", "普通 info 信息");
        bindingKeyMap.put("warning", "警告 warning 信息");
        bindingKeyMap.put("error", "错误 error 信息");
        //debug 没有消费者接收这个消息 消息就丢失了
        bindingKeyMap.put("debug", "调试 debug 信息");

        for (Map.Entry<String, String> entry : bindingKeyMap.entrySet()) {
            String routingKey = entry.getKey();
            String message = entry.getValue();

            channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
            System.err.println("发送消息完成:" + message);
        }


    }
}

